package org.tradeinterceptor.modular.strategy.modules;

import org.tradeinterceptor.modular.strategy.ForexSignal;
import org.tradeinterceptor.modular.strategy.StrategyModule;

import com.riflexo.charting.api.AbstractEasyCalculator;
import com.riflexo.charting.api.NumberValueDescriptor;
import com.riflexo.charting.api.Param;
import com.riflexo.charting.api.StockIndicator;


public class EMAStrategyModule implements StrategyModule {

	private StockIndicator<Object> movingAverage1;
	int period1;
	
	private StockIndicator<Object> movingAverage2;
	int period2;
	
	public EMAStrategyModule(int period1, int period2) {
		// TODO Auto-generated constructor stub
		this.period1 = period1;
		this.period2 = period2;
	}
	
	@Override
	public ForexSignal getSignal() {
		// TODO Auto-generated method stub
		ForexSignal signal = ForexSignal.NONE;
		if(movingAverage1.get() > movingAverage2.get()){
			signal = ForexSignal.BUY;
		} else if(movingAverage1.get() < movingAverage2.get()){
			signal = ForexSignal.SELL;
		}
		return signal;
	}
	
	@Override
	public void setPosition(ForexSignal signal) {
		//non positional module
	}

	@Override
	public void declare(AbstractEasyCalculator parent) {
		// TODO Auto-generated method stub
		
		movingAverage1 = parent.getStockIndicatorUtil()
				.declareExponentialMovingAverage("ema" + period1,
						period1);
		movingAverage2 = parent.getStockIndicatorUtil()
				.declareExponentialMovingAverage("ema" + period2,
						period2);

	}
	
	@Override
	public void close() {
		// TODO Auto-generated method stub
		
	}

}
